import urllib.request


def load_baidu():
    url = "http://www.baidu.com/"
    header = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36"
    }

    # 创建请求头对象
    request = urllib.request.Request(url, headers=header)
    response = urllib.request.urlopen(request)

    data = response.read().decode('utf-8')

    with open("02header.html","w",encoding="utf-8") as f:
        f.write(data)

load_baidu()
